

#include "wxsSTEditor.h"


namespace
{


    #include "STE16.xpm"
    #include "STE32.xpm"

    wxsRegisterItem<wxsSTEditor> Reg(
        _T("wxSTEditor"),          
        wxsTWidget,                    
        _T("wxWindows"),               
        _T("Ron Collins"),             
        _T("rcoll@theriver.com"),      
        _T(""),                        
        _T("Styled Text"),             
        55,                            
        _T("STE"),                     
        wxsCPP,                        
        1, 0,                          
        wxBitmap(STE32_xpm),           
        wxBitmap(STE16_xpm),           
        false);                        


    WXS_ST_BEGIN(wxsSTEditorStyles,_T("wxRE_MULTILINE|wxRAISED_BORDER|wxWANTS_CHARS"))
        WXS_ST_CATEGORY("wxSTEditor")

        WXS_ST_DEFAULTS()
    WXS_ST_END()

    WXS_EV_BEGIN(wxsSTEditorEvents)

       WXS_EVI(EVT_TEXT_ENTER,                    wxEVT_COMMAND_TEXT_ENTER,                    wxCommandEvent,  EvTextEnter)
       WXS_EVI(EVT_TEXT,                          wxEVT_COMMAND_TEXT_UPDATED,                  wxCommandEvent,  EvTextUpdated)
       WXS_EVI(EVT_TEXT_URL,                      wxEVT_COMMAND_TEXT_URL,                      wxTextUrlEvent,  EvTextURL)

        WXS_EV_DEFAULTS()
    WXS_EV_END()
}


wxsSTEditor::wxsSTEditor(wxsItemResData* Data):
    wxsWidget(
        Data,
        &Reg.Info,
        wxsSTEditorEvents,
        wxsSTEditorStyles) {
    mSize.Set(32, 32);
    mText.Clear();
    mVirtualSize.IsDefault = true;

}


void wxsSTEditor::OnBuildCreatingCode() {
wxString            vname;
wxString            aname;
wxString            ss, tt;
wxColour            fg;


    if (GetLanguage() != wxsCPP) wxsCodeMarks::Unknown(_T("wxsSTEditor::OnBuildCreatingCode"),GetLanguage());


    vname = GetVarName();
    aname = vname + _T("_Attr");


    AddHeader(_("\"stedit.h\""), GetInfo().ClassName, 0);


    mSize.SetDefaults(wxSize(32, 32));
    ss.Printf(_T("wxSize(%d, %d)"), mSize.GetWidth(), mSize.GetHeight());


    Codef(_T("%C(%W, %I, %P, %s, %T, %N);\n"), ss.c_str());


    BuildSetupWindowCode();


    if (! mVirtualSize.IsDefault) {
        ss = mVirtualSize.GetSizeCode(GetCoderContext());
        Codef(_T("%ASetVirtualSize(%s);\n"), ss.c_str());
    };


    for(size_t i=0; i<mText.GetCount(); i++) {
        ss  = mText.Item(i);
        ss += _T("\n");
        Codef(_T("%AAppendText(%t);\n"), ss.c_str());
    };
}


wxObject* wxsSTEditor::OnBuildPreview(wxWindow* Parent, long Flags) {
wxSTEditor          *ste;
wxColour            fg;
wxString            ss;
wxSize              zz;



    mSize = Size(Parent);
    mSize.SetDefaults(wxSize(32, 32));


    ste = new wxSTEditor(Parent, GetId(), Pos(Parent), mSize, Style());


    SetupWindow(ste, Flags);


    if (! mVirtualSize.IsDefault) {
        zz = mVirtualSize.GetSize(Parent);
        ste->SetVirtualSize(zz);
    };


    for(size_t i=0; i<mText.GetCount(); i++) {
        ss  = mText.Item(i);
        ss += _T("\n");
        ste->AppendText(ss);
    };


    return ste;
}


void wxsSTEditor::OnEnumWidgetProperties(long Flags) {


    WXS_ARRAYSTRING(wxsSTEditor, mText, _("Text"), _("mText"), _("text"));
    WXS_SIZE(       wxsSTEditor, mVirtualSize,   _T("Default Virtual Size?"),           _T("Virtual Width"),    _T("Virtual Height"), _T("Use Dialog Units?"), _T("mVirtualSize"));

};
